package android.controller;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.util.Log;

public class EncriptController {
	String namespace = "http://192.168.1.9:8085/service/application/servicio_prueba/servicio_scriptSOA.php";
	String URL = "http://192.168.1.9:8085/service/application/servicio_prueba/servicio_scriptSOA.php";

	/**
	 * Registro de Administrador
	 * @param usuario
	 * @param clave
	 * @param token
	 * @return
	 */
	public String registrarAdministrador(String usuario, String clave, String token){

		String method = "registrarAdministrador";
		String SOAP_ACTION = namespace+"#"+method;

		SoapObject request = new SoapObject(namespace, method);

		request.addProperty("usuario", usuario);
		request.addProperty("clave", clave);
		request.addProperty("token", token);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

		try {			
			androidHttpTransport.call(SOAP_ACTION, envelope);			
			return envelope.getResponse().toString();
		} catch (Exception e) {
			e.printStackTrace();
			Log.i(method, " error: " + e);
			return "Error de conexion con WS";
		}

	}
   /**
    * Login para ingreso de Administrador
    * @param usuario
    * @param clave
    * @return
    */
	public String loginAdministrador(String usuario, String clave){

		String method = "loginAdministrador";
		String SOAP_ACTION = namespace+"#"+method;

		SoapObject request = new SoapObject(namespace, method);

		request.addProperty("usuario", usuario);
		request.addProperty("clave", clave);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

		try {			
			androidHttpTransport.call(SOAP_ACTION, envelope);			
			return envelope.getResponse().toString();
		} catch (Exception e) {
			e.printStackTrace();
			Log.i(method, " error: " + e);
			return "Error de conexion con WS";
		}

	}
    /**
     * Encriptar
     * @param cadena
     * @param token
     * @return String
     */
	public String encriptar(String cadena, String token){

		String method = "encriptar";
		String SOAP_ACTION = namespace+"#"+method;

		SoapObject request = new SoapObject(namespace, method);

		request.addProperty("cadena", cadena);
		request.addProperty("token", token);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

		try {			
			androidHttpTransport.call(SOAP_ACTION, envelope);			
			return envelope.getResponse().toString();
		} catch (Exception e) {
			e.printStackTrace();
			Log.i(method, " error: " + e);
			return "Error de conexion con WS";
		}

	}
    /**
     * Desencriptar
     * @param cadena
     * @param token
     * @return
     */
	public String desencriptar(String cadena, String token){

		String method = "desencriptar";
		String SOAP_ACTION = namespace+"#"+method;

		SoapObject request = new SoapObject(namespace, method);

		request.addProperty("cadena", cadena);
		request.addProperty("token", token);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

		try {			
			androidHttpTransport.call(SOAP_ACTION, envelope);			
			return envelope.getResponse().toString();
		} catch (Exception e) {
			e.printStackTrace();
			Log.i(method, " error: " + e);
			return "Error de conexion con WS";
		}

	}
    /**
     * Validacion de Login
     * @param token
     * @return
     */
	public static String validarLogin(String token){
		
		String namespace = "http://192.168.1.9:8085/service/application/servicio_prueba/servicio_scriptSOA.php";
		String URL = "http://192.168.1.9:8085/service/application/servicio_prueba/servicio_scriptSOA.php";

		String method = "validarLogin";
		String SOAP_ACTION = namespace+"#"+method;

		SoapObject request = new SoapObject(namespace, method);

		request.addProperty("token", token);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

		try {
			androidHttpTransport.call(SOAP_ACTION, envelope);
			return envelope.getResponse().toString();
		} catch (Exception e) {
			e.printStackTrace();
			Log.i(method, " error: " + e);
			return "Error de conexion con WS";
		}

	}

	

}
